home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Online / News / Thor / rexx / MailtoScripts / IBMailTo.thor < prev    next >
Encoding:
Text File  |  1996-11-11  |  6.6 KB  |  235 lines

  1. /*
  2. ** $VER: IBMailTo.thor v1.1 (14/08/96) John S. Burger.
  3. **               <jsburger@xmission.com>
  4. **
  5. ** This script borrows heavily from AwebMailTo.thor by Shaun Downend.
  6. **                  <shaund@amiganut.demon.co.uk>
  7. **                         Thanks Shaun!!!
  8. **
  9. ** This script is designed for use with IBrowse's external mailto: support.
  10. ** It will take the email address supplied by IBrowse and start the text
  11. ** editor of your choice and automatically fill in the To: field. When you
  12. ** have finished you save the message and it will appear as an event in Thor.
  13. **
  14. ** See the .readme file for configuration information.
  15. */
  16.  
  17. /* User defined variables */
  18.  
  19. MailSystem = 'Internet'                              /* Set to your TCP System in Thor */
  20. MailConfName = 'EMail'                               /* Set to your Email Conference in Thor */
  21. AddSignature = 'E'                                   /* Add signature (Y/N/E) from Thor or 'E' for another signature file*/
  22. SigFile = 'DH3:Thor/IB.signature'                    /* File name with path for a signature file used with the 'E' option above */
  23. SendEvent  = 'N'                                     /* Send event immediately (Y/N)  */
  24. Editor = 'GED -STICKY C=DH1:GoldEd/config/IB.prefs'  /* Set to the editor of your choice */
  25.  
  26. /* DON'T CHANGE ANYTHING BELOW HERE */
  27.  
  28. Tempfile = 't:MailTo.msg.'||time(s)'.ib'
  29.  
  30. parse arg argument
  31.  
  32. template = 'ADDRESS/A'
  33.  
  34. if(argument = '' | argument = '?') then
  35. do
  36.     say '$VER: IBMailTo.thor V1.0 (13/08/96) John S. Burger'
  37.     say 'Template:' template
  38.     exit
  39. end
  40.  
  41. if ~show('p', 'BBSREAD') then
  42. do
  43.     address command
  44.     "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  45.     "sys:rexxc/WaitForPort BBSREAD"
  46. end
  47.  
  48.  
  49. address BBSREAD
  50.  
  51. READARGS template ARGS CMDLINE argument
  52. if(rc ~= 0) then
  53. do
  54.     say BBSREAD.LASTERROR
  55.     exit
  56. end
  57.  
  58. address command 'echo >'tempfile' "To: 'ARGS.ADDRESS'*NSubject: *N"'
  59. address command ''Editor' 'tempfile''
  60.  
  61. if(~OPEN(fh,tempfile,'Read')) then
  62. do
  63.     say 'Unable to open file'
  64.     exit
  65. end
  66.  
  67. str = readln(fh)
  68. if(upper(word(str, 1)) ~= "TO:") then
  69.  
  70. do
  71.     call showerror("First headerline wasn't a To:, please don't mess with the header IBrowse provides.")
  72.     call close(fh)
  73.     address command 'c:delete >NIL: 'tempfile''
  74.     exit
  75. end
  76. else EVENT.TOADDR = word(str, 2)
  77.  
  78. str = readln(fh)
  79.  
  80. if(upper(word(str, 1)) ~= "SUBJECT:") then
  81. do
  82.     call showerror("Second headerline wasn't a Subject:, please don't mess with the header IBrowse provides.")
  83.     call close(fh)
  84.     address command 'c:delete >NIL: 'tempfile''
  85.     exit
  86. end
  87. else EVENT.SUBJECT = substr(str, 10)
  88. if(upper(word(str, 2)) = "") then
  89. do
  90.     call showerror("Mail Discarded by User")
  91.     call close(fh)
  92.     address command 'c:delete >NIL: 'tempfile''
  93.     exit
  94. end
  95.  
  96. /* skip X-Mailer: line */
  97.  
  98. call readln(fh)
  99.  
  100. /* put the body of the message in a file with a unique name */
  101.  
  102. UNIQUEMSGFILE bbsname '"'MailSystem'"' stem UNIQUEFILE
  103. if(rc ~= 0) then
  104. do
  105.     call showerror('UNIQUEMSGFILE BBSRead command failed: ' || BBSREAD.LASTERROR)
  106.     call close(fh)
  107.     address command 'c:delete >NIL: 'tempfile''
  108.     exit
  109. end
  110.  
  111. call open(tmp, UNIQUEFILE.NAME, W)
  112.  
  113. do until eof(fh)
  114.     call writeln(tmp, readln(fh))
  115. end
  116.  
  117. /* add signature from the EMail conference/BBS/Global Settings */
  118.  
  119. if(upper(AddSignature) = 'Y') then
  120. do
  121.     GETCONFDATA BBSNAME '"'MailSystem'"' CONFNAME '"'MailConfName'"' STEM CONFD
  122.     if(CONFD.SIGNATURE = "") then
  123.     do
  124.         GETBBSDATA BBSNAME '"'MailSystem'"' STEM BBSD
  125.         if(BBSD.SIGNATURE = "") then
  126.         do
  127.             GETGLOBALDATA STEM GLOBD
  128.             if(GLOBD.SIGNATURE = "") then
  129.             do
  130.                 call showerror('No signature configured in either conference, bbs or global settings! Please correct this in THOR or turn off signature adding in IBMailTo.thor.')
  131.                 call close(fh)
  132.                 address command 'c:delete >NIL: 'tempfile''
  133.                 exit
  134.             end
  135.             else sig = GLOBD.SIGNATURE
  136.         end
  137.         else sig = BBSD.SIGNATURE
  138.     end
  139.     else sig = CONFD.SIGNATURE
  140.  
  141.     drop CONFD.; drop BBSD.; drop GLOBD.
  142.  
  143.     if(sig ~= "") then
  144.     do
  145.     /* signature may be a filename */
  146.  
  147.         if(exists(sig)) then
  148.         do
  149.             call open(sigfh, sig, R)
  150.  
  151.             do until eof(sigfh)
  152.                 call writeln(tmp, readln(sigfh))
  153.             end
  154.  
  155.             call close(sigfh)
  156.         end
  157.         else call writeln(tmp, sig) /* or just a string */
  158.     end
  159. end
  160.  
  161. if(upper(AddSignature) = 'E') then
  162. do
  163.   if(exists(SigFile)) then
  164.   do
  165.      call open(sigfh, SigFile, R)
  166.      do until eof(sigfh)
  167.         call writeln(tmp, readln(sigfh))
  168.      end
  169.      call close(sigfh)
  170.   end
  171.   else
  172.     do
  173.       call showerror('The configured signature file does not exist! Please correct this or turn off signature adding in IBMailTo.thor.')
  174.       call close(fh)
  175.       address command 'c:delete >NIL: 'tempfile''
  176.       exit
  177.     end
  178. end
  179. call close(tmp)
  180.  
  181. /* fill out some more variables that BBSREAD require */
  182.  
  183. EVENT.CONFERENCE = MailConfName
  184. EVENT.MSGFILE = UNIQUEFILE.FILEPART
  185.  
  186. /* write the event */
  187.  
  188. WRITEBREVENT bbsname '"'MailSystem'"' event 0 stem EVENT
  189. if(rc ~= 0) then
  190. do
  191.     call showerror('WRITEBREVENT BBSRead command failed: ' || BBSREAD.LASTERROR)
  192.     call close(fh)
  193.     address command 'c:delete >NIL: 'tempfile''
  194.     exit
  195. end
  196.  
  197. call close(fh)
  198.  
  199. address command 'c:delete >NIL: 'tempfile''
  200.  
  201. if upper(sendevent) = "Y" then call send
  202.  
  203. exit 0
  204.  
  205. /* sophisticated errorhandling :-) */
  206.  
  207. showerror:
  208.  
  209. procedure expose MailSystem MailConfName AddSignature SigFile Editor
  210. parse arg errormsg
  211.  
  212. p=show('P',,)
  213.  
  214. if(pos('IBROWSE', p) > 0) then IBport = word(substr(p, pos('IBROWSE', p)), 1)
  215. else return
  216.  
  217. call open(err, "T:IBMailTo.thor.error.html", W)
  218. call writeln(err, "<HTML><HEAD><TITLE>IBMailTo.thor encountered an error</TITLE></HEAD><BODY><H1>Sending mail aborted</H1>" || errormsg || "<P>Please remember to verify the following settings:<PRE>" || '0a'x '0a'x || "MailSystem = '" || MailSystem || "'" || '0a'x || "MailConfName = '" || MailConfName || "'" || '0a'x || "AddSignature = '" || AddSignature || "'" || '0a'x || "SigFile = '" || SigFile || "'" || '0a'x || "Editor = '" || Editor || "'" || '0a'x '0a'x || "</PRE>If they are wrong, edit IBMailTo.thor and correct them. <hr> If this should happen to be an erroneous error, don't hesitate to contact the author, John S. Burger, by <A HREF=" || '"' || "mailto:jsburger@xmission.com" || '"' || ">email</A>.")
  219. call close(err)
  220.  
  221. address(IBport)
  222. 'GOTOURL URL file://localhost/T:IBMailTo.thor.error.html'
  223. return
  224.  
  225. send:
  226.  
  227. If Show('p', 'AMITCP') | Show('p', 'MIAMI.1') = 1 then
  228. do
  229.     address BBSREAD
  230.     GETBBSDATA SystemName stem BBSDATA
  231.     if BBSDATA.NUMEVENTS ~= 0 then
  232.     address command 'run >NIL: `getenv thor/thorpath`bin/SendTCP 'MailSystem' pubscreen=Workbench'
  233. end
  234. return
  235.